package com.example.week14.util;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class JDBCUtil {
    static String url = "jdbc:mysql://localhost:3306/db_library";
    static String username = "root";
    static String password = "123456";

    public static Connection getConnection() {
        Connection conn = null;
        try {
            conn = DriverManager.getConnection(url, username,
                    password);
        } catch (SQLException e) {
            e.printStackTrace();
        }
        return conn;
    }

    public static void main(String[] args) throws Exception {
        try (Connection conn = JDBCUtil.getConnection()) {
            System.out.println("数据库连接成功");
        }
    }
}
